<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Organization Chart Plugin</title>
  <link rel="icon" href="img/logo.png">
  <link rel="stylesheet" href="css/font-awesome.min.css">
  <link rel="stylesheet" href="css/jquery.orgchart.css">
  <link rel="stylesheet" href="css/style.css">
  <style type="text/css">
    .orgchart { background: white; }
  </style>
</head>
<body>
  <div id="chart-container"></div>

  <script type="text/javascript" src="js/jquery.min.js"></script>
  <script type="text/javascript" src="js/jquery.orgchart.js"></script>
  <script type="text/javascript">
    $(function() {

      var datascource = {
        'name': 'Lao Lao',
        'title': 'general manager',
        'children': [
          { 'name': 'Bo Miao', 'title': 'department manager' },
          { 'name': 'Su Miao', 'title': 'department manager',
            'children': [
              { 'name': 'Tie Hua', 'title': 'senior engineer' },
              { 'name': 'Hei Hei', 'title': 'senior engineer',
                'children': [
                  { 'name': 'Pang Pang', 'title': 'engineer' },
                  { 'name': 'Dan Zai', 'title': 'UE engineer',
                    'children': [
                      { 'name': 'Er Dan Zai', 'title': 'Intern' }
                    ]
                  }
                ]
              }
            ]
          },
          { 'name': 'Hong Miao', 'title': 'department manager' },
          { 'name': 'Chun Miao', 'title': 'department manager' }
        ]
      };

      $('#chart-container').orgchart({
        'visibleLevel': 2,
        'pan': true,
        'data' : datascource,
        'nodeContent': 'title',
        'createNode': function($node, data) {
          $node.on('click', function(event) {
            if (!$(event.target).is('.edge, .toggleBtn')) {
              var $this = $(this);
              var $chart = $this.closest('.orgchart');
              var newX = window.parseInt(($chart.outerWidth(true)/2) - ($this.offset().left - $chart.offset().left) - ($this.outerWidth(true)/2));
              var newY = window.parseInt(($chart.outerHeight(true)/2) - ($this.offset().top - $chart.offset().top) - ($this.outerHeight(true)/2));
              $chart.css('transform', 'matrix(1, 0, 0, 1, ' + newX + ', ' + newY + ')');
            }
          });
        }
      });

    });
  </script>
  </body>
</html>